package com.system.utils;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class ContextUtil {

	private static ApplicationContext context;
	
	static {
		ServletContext sc = ContextLoader.getCurrentWebApplicationContext().getServletContext();
		 
		context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		
	}
	
	
	public static <T>T getBean(String beanName){
		return (T) context.getBean(beanName);
	}
	 
	// 鑾峰彇bean 鏂规硶2
	public static <T> T getBean(Class<T> c){
		return (T) context.getBean(c);
	}
	
}
